package com.mnsq.im.bean;

import com.mnsq.im.enums.MessageType;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.util.Base64Utils;
import org.springframework.util.StringUtils;

import javax.persistence.Transient;

/**
 * @author zj00924
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
public class SocketMessage {
    private MessageType messageType;
    private String content;
    private String picContent;
    private String token;
    private String picInfo;
    private String group;
    private String headPicSmall;
    private String userName;
    private int total;

    @Transient
    public String easyContent() {
        if (!StringUtils.isEmpty(this.content)) {
            byte[] decode = Base64Utils.decode(this.content.getBytes());
            return new String(decode);
        }
        return "";
    }

    public SocketMessage setContent(String content){
        this.content = new String(Base64Utils.encode(content.getBytes()));
        return this;
    }
}
